﻿#pragma once
#include "common.h"

#include <QMainWindow>
#include "ui_TranscodeWindow.h"

//#include <QFileDialog>
//#include <QFileInfo>
//#include <QMessageBox>
//#include <QPushButton>
//#include <QThread>
//#include <QCloseEvent>
//#include <QDebug>
//#include <atomic> // 原子头文件用于多线程全局标志

// include transcode header file
#include "FFmpegTranscoding.h"
// PCM 选择窗口
#include "OpenPCMWindow.h"


class TranscodeWindow : public QMainWindow
{
	Q_OBJECT

public:
	TranscodeWindow(QWidget *parent = nullptr);
	~TranscodeWindow();

	bool isClosed() const;


signals:
	void closeSignal(void); // close and delete transcoding object

	void showMainWindowSignal(void); // show main window after transcoding finished

private slots:
	void transcodeStart();

	void openInputFile();
	void openOutputPath();
	void getOutAudioSuffix(int index);
	void finishedSlot(int64_t time_now);
	void inoutPcmWindowClose();
	//void startInSubThread(); // 在子线程中运行转码程序


protected:
	void closeEvent(QCloseEvent *event) override;


private:
	void runTranscoder();

	Ui::TranscodeWindowClass ui;
	// �����Ƿ�ر�
	bool window_closed;

	// transcoding object
	AudioTranscoder* transcoder;
	std::string input_file;
	std::string output_file;
	std::string input_file_suffix;
	std::string output_file_suffix;
	int64_t		start_time;

	// PCM 窗口对象
	OpenPCMWindow* input_pcm_window;
	OpenPCMWindow* output_pcm_window;
	char inout_window_count; // 引用窗口计数
	std::thread transcodeThread; // 子线程
	//std::atomic<bool> isTranscoding;
};

